#include "UUnitOrBuilding.h"
#include "UUnitOrBuildingType.h"

using namespace std;

TUnitOrBuilding::TUnitOrBuilding(int PosX, int PosY, float PosZ)
{
	X = PosX;
	Y = PosY;
	Z = PosZ;
	IsSelected = false;
}

void TGUIUnitOrBuilding::Draw()
{
	if (UnitBuilding->Type->HasModel)
	{
		glPushMatrix();
		glTranslatef(UnitBuilding->X, UnitBuilding->Y, UnitBuilding->Z);
		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);

		glEnable(GL_CULL_FACE);

		UnitBuilding->Type->TypeModel->draw();

		glDisable(GL_CULL_FACE);
		glDisable(GL_LIGHTING);
		glDisable(GL_LIGHT0);
		glPopMatrix();

	}
	else
	{
		glDisable(GL_LIGHTING);
		glColor3f(1, 1, 1);

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, Type()->Icon);

		glBegin(GL_QUADS);
			glTexCoord2i(0,0); glVertex3f(UnitBuilding->X				, UnitBuilding->Y				, UnitBuilding->Z+0.3);
			glTexCoord2i(1,0); glVertex3f(UnitBuilding->X+Type()->Width	, UnitBuilding->Y				, UnitBuilding->Z+0.3);
			glTexCoord2i(1,1); glVertex3f(UnitBuilding->X+Type()->Width	, UnitBuilding->Y+Type()->Height, UnitBuilding->Z+0.3);
			glTexCoord2i(0,1); glVertex3f(UnitBuilding->X				, UnitBuilding->Y+Type()->Height, UnitBuilding->Z+0.3);
		glEnd();

		glDisable(GL_TEXTURE_2D);

		//get screen coordinates
/*		if (IsSelected)
		{
			GLdouble _x, _y, _z ;

			gluProject(X+Type()->Width/2, Y+Type()->Height/2, Z, model_view, projection, viewport, &_x	, &_y	, &_z);

			BuildingHealthBars.push_back(TRectangle(_x-5, _y, _x+5, _y+2));
		}*/
	//get screen coordinates
	}
}


